<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/17/017
 * Time: 11:16
 */

namespace app\Lib\Ioc\Tag;


use app\Lib\Model\Tag\HouseTypeTag\AddHouseTypeTag;
use app\Lib\Model\Tag\HouseTypeTag\EditHouseTypeTag;
use app\Lib\Model\Tag\HouseTypeTag\GetHouseTypeTagList;
use app\Lib\Model\Tag\HouseTypeTag\GetInfo;
use app\Lib\Model\Tag\HouseTypeTag\HouseTypeTagSelectList;
use app\Lib\Model\User\User;
use think\Db;

class HouseTypeTag
{
    /**
     * 添加操作
     * @param array $data
     * @return bool
     * @throws \app\Lib\Exception\BlException
     */
    public function AddTag($data = []){
        $model = new AddHouseTypeTag();
        $model->setTagName($data['name']);
        $model->setOpUser(new User($data['opUid']));
        if(!empty($data['imgId'])){
            $model->setImgId($data['imgId']);
        }
        $model->run();
        return true ;
    }

    /**
     * 修改
     * @param array $data
     * @return bool
     * @throws \app\Lib\Exception\BlException
     */
    public function editTag($data = []){
        $result = Db::transaction(function ()use ($data){
            $model = (new EditHouseTypeTag($data['id']));
            $model->setOpUser(new User($data['opUid']));
            $model->setTagName($data['name']);
            if(!empty($data['imgId'])){
                $model->setImgId($data['imgId']);
            }
            $model->run();
            return true;
        });
        if($result){
            (new \app\Lib\Model\Tag\HouseTypeTag\HouseTypeTag($data['id']))->delAllCache();
        }
        return true ;
    }

    /**
     * 列表数据
     * @param $data
     * @return array|string
     */
    public function getList($data){
        $model =  (new GetHouseTypeTagList());
        $model->setLimit($data['limit']);
        $model->setPage($data['page']);
        $model->setType('HouseType');
        return $model->run();
    }

    /**
     * 总数据量
     * @return string
     */
    public function getCount(){
        $model =  (new GetHouseTypeTagList());
        $model->setIsPage(true);
        return  $model->run();
    }

    /**
     * 获取标签详情
     * @param $data
     * @return array
     */
    public function getInfo($data){
        return (new GetInfo(new \app\Lib\Model\Tag\HouseTypeTag\HouseTypeTag($data['id'])))->run();
    }

    public function getTagList(){
        $model =  (new HouseTypeTagSelectList());
        $list  = $model->getList();
        return $list;
    }
}